<template>
  <div>
    <goga-header title="消息中心">
      <div slot="left">
        <span @click="goBack">
          <icon symbol="back"> </icon>
        </span>
      </div>
    </goga-header>
    <img v-if="firstLoading" class="gxb-loading" src="/public/images/loding.gif" alt="">
    <div class="empty" v-if="!firstLoading&&message.list.length ==0 ">
      <span>目前没有消息</span>
    </div>
    <div v-if="message.list.length !=0">
      <div class="message-list">
        <div class="item" v-for="(item, index) in message.list" :key="item.id">
          <div class="p-content">
            {{item.mContent}}
          </div>
          <div class="p-date">
            {{item.changeDate}}
          </div>
        </div>
      </div>
      <div v-if="message.pageNum>message.page">
        <div class="list-loading"v-if="loading" >
          <img src="/public/images/loading-min.gif" alt="">
        </div>
        <div class="list-loadmore" >
          <button class="loadmore-btn" @click="loadMore">
            加载更多消息
          </button>
        </div>
      </div>
      <div class="list-complete" v-if="message.pageNum!=0 && (message.pageNum<=message.page)">
        <img src="/public/images/min-logo.png" alt="">
      </div>
    </div>
  </div>
</template>

<script lang="babel">
  import {mapGetters} from 'vuex'
  import gogaHeader from '@components/goga-header'
  import Icon from '@components/icon'
  const fetchMessageData = async (store, page) => {
    return await store.dispatch('backend/message/getMessage', page)
  }
  export default {
    components: {
      gogaHeader,
      Icon
    },
    data () {
      return {
        firstLoading: true,
        loading: false
      }
    },
    computed: {
      ...mapGetters({
        message: 'backend/message/getMessage'
      })
    },
    async mounted () {
      this.firstLoading =false;
    },

    methods: {
      goBack() {
        this.$router.go(-1);
      },
      loadMore() {
        let page = this.message.page + 1;
        if(page <= this.message.pageNum) {
          this.loading = true;
          fetchMessageData(this.$store, page);
          this.loading = false;
        }
      }
    }
  }
</script>

<style lang="less">
  @import "index.less";
</style>
